package com.kfm.jdbc.day0328;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public interface Actor {

    void sing(double money);

    void jump(double money);
}

class Kun implements Actor{

    @Override
    public void sing(double money) {
        System.out.println("收了" + money + "元，唱了一首《只因你太美》");
    }

    @Override
    public void jump(double money) {
        System.out.println("收了" + money + "元，跳了一个舞");
    }
}

class Agent implements Actor{

    private Actor actor;
    public Agent(Actor actor){
        this.actor = actor;
    }


    @Override
    public void sing(double money) {
        this.actor.sing(money * 0.8);
    }

    @Override
    public void jump(double money) {
        this.actor.jump(money * 0.9);
    }
}


class Main {

    public static void main(String[] args) {
        Kun kun = new Kun();

        Actor o = (Actor) Proxy.newProxyInstance(Kun.class.getClassLoader(),
                new Class[]{Actor.class},
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        String name = method.getName();
                        if ("sing".equals(name)){
                            System.out.println("请他唱歌先请我吃饭");
                            return method.invoke(kun, args);
                        } else {
                            System.out.println("做其他事得加钱");
                            return method.invoke(kun, args);
                        }
                    }
                }
        );

        o.sing(1.1);
        o.jump(2.2);
//        Agent agent = new Agent(kun);
//        agent.sing(50000);
    }
}
